#!/bin/sh

# Dependencies: libglib2.0 libgtk2.0 libpango1.0 libglib2.0-dev libgtk2.0-dev libpango1.0-dev

apt-get install libglib2.0-0 \
                libgtk2.0-0 \
		libpango1.0-0 \
		libglib2.0-dev \
		libgtk2.0-dev \
		libpango1.0-dev

if ! md5sum -c --status md5sums 
then
  echo "install.sh: files are corrupted."
  exit 0
fi

if [ ! -e /usr/bin/update-mime-database ]
then
  echo "install.sh: update-mime-database is missing."
  exit 0
fi

if [ ! -e /usr/bin/update-desktop-database ]
then
  echo "install.sh: update-desktop-database is missing."
  exit 0
fi

gcc -o /usr/bin/bnc bnc.c manager.c compressor.c cryptor.c stack.c node.c
gcc -o /usr/bin/bnc-gtk bnc-gtk.c manager-gtk.c \
`pkg-config --cflags --libs gtk+-2.0`

mkdir -p /usr/share/pixmaps
mkdir -p /usr/share/icons/gnome/48x48/mimetypes

cp bnc.png /usr/share/pixmaps/bnc.png
cp bnc.png /usr/share/icons/gnome/48x48/mimetypes/application-x-bnc.png

mkdir -p /usr/share/mime/packages
mkdir -p /usr/share/applications

cp bnc.xml /usr/share/mime/packages/bnc.xml
cp bnc.desktop /usr/share/applications/bnc.desktop

update-mime-database /usr/share/mime

touch /usr/share/applications/mimeapps.list

# [Added Associations]
# application/x-bnc=bnc.desktop;

if [ `grep -c "^\[Added Associations\]$" /usr/share/applications/mimeapps.list` -eq 0 ]
then
 echo "[Added Associations]" >> /usr/share/applications/mimeapps.list
fi

ed /usr/share/applications/mimeapps.list << END
g/^application\/x-bnc=bnc\.desktop;$/d
/^\[Added Associations\]$/a
application/x-bnc=bnc.desktop;
.
wq
END

update-desktop-database

echo "install.sh: bnc has just been installed!"
exit 0
